{% extends 'main.html' %}
{% load func %}

{% block title %}
    <title>tag admin</title>
{% endblock %}


{% block content %}
<center><h4 style="color: red" id="error"></h4></center>
<div class="panel">
    <div class="panel-heading">
        <h3 class="panel-title">标签列表</h3>
    </div>
    <div class="panel-body">
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>标签名称</th>
                        <th>操    作</th>
                    </tr>
                </thead>
                <tbody>
                {% for tag in tag_obj %}
                    <tr>
                        <td>{{ tag.name }}</td>
                        <td><button class="label label-danger" id="{{ tag.id }}" onclick="del(this)">删除</button></td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>



<div class="panel-body ">
    <div class="panel-heading ">
        <h3 class="panel-title">增加新标签</h3>
    </div>
    <div class="panel">
        <form class="form-horizontal" method="POST">
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-sm-3 control-label" for="demo-is-inputsmall">{{ obj.name.label }}</label>
                    <div class="col-sm-6">
                    <p>{{ obj.name }}</p>
                    <p style="color: red">{{ obj.name.errors.0 }}</p>
                    </div>
                </div>
                </div>
            <div class="panel-footer">
                <div class="row">
                    <div class="col-sm-9 col-sm-offset-3">
                        <button class="btn btn-mint" type="submit" onclick="save()">保存</button>
                        <button class="btn btn-warning" type="reset">重填</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
   function del(eml){
        var tag_id=$(eml).attr('id');
        if(confirm('是否删除标签？删除前请保证无资产关联到此标签，否则会导致失败')){
            $.ajax({
                url:'/tag_mgr/',
                type:'DELETE',
                data:{'tag_id':tag_id},
                success:function(arg){
                    if(arg == 0){
                        location.reload()
                    }
                    else {
                        $('#error').text('删除失败！！请先删除关联到此标签的资产！！')
                    }
                }
            })
        }
    }
</script>
{% endblock %}
